<?php
$T->loadTpl("./html/".$template."/".$qname.".html");
$T->SetTpl('cssjs','html/cssjs.inc'); 
$T->SetTpl('jsmodel','html/jsmodel.inc');

function Recombination($arr,$id='id',$name='name'){
    $newArr = array();
    foreach($arr as $val){
        $newArr[$val[$id]] = $val[$name];// = $val['id'];
    }
    return $newArr;
}
//                  0       1     2       3       4        5      6       7       8       9       10
$REPAIR_STATUS = ['全部','已申请','修复中','已维修','已结束','待评价','已评价','已撤回','待维修','已拒绝','无法维修'];
$id=isset($_GET["id"])?$_GET["id"]:"0";
if($id!="0") {
    $user_list = $T->db->query("SELECT id,deptname FROM sys_department")->fetchAll(PDO::FETCH_ASSOC);
    $userlist = Recombination($user_list,'id','deptname');;
    $repair_type = $T->db->query("select id,name from sys_equipment_repair where is_flag_delete = 0")->fetchAll(PDO::FETCH_ASSOC);
    $arrlist =  Recombination($repair_type,'id','name');
    $dict = $T->db->query("SELECT * FROM sys_takes_list where id = ".$id)->fetch(PDO::FETCH_ASSOC);

    if($dict["takes_user"] == '待指定'){
        $takes_user = "待指定";
    }else{
        $member = $T->db->query("select id,truename from sys_member")->fetchAll(PDO::FETCH_ASSOC);
        $member_list =  Recombination($member,'id','truename');
        $takes_user = $member_list[$dict["takes_user"]];
    }
    if($dict["agent"] == ""){
        $dict["agent"] = "无";
    }
    $dict["evaluate"] = $dict["evaluate"]."<br/>".$dict["add_evaluate"];
    //print_r($takes_user);exit;
    $T->Set("id",$dict["id"]);
    $T->Set("release_user", $dict["release_user"]);
    $T->Set("agent", $dict["agent"]);
    $T->Set("takes_type", $arrlist[$dict["takes_type"]]);
    $T->Set("code", $dict["code"]);
    $T->Set("takes_user", $takes_user);
    $T->Set("contact_phone", $dict["contact_phone"]);
    $T->Set("release_time", $dict["release_time"]);
    $T->Set("takes_time", $dict["takes_time"]);
    $T->Set("project_type", $dict["project_type"]);
    $T->Set("release_user_id", $dict["release_user_id"]);
    $T->Set("department", $userlist[$dict["department"]]);
    $T->Set("takes_address", $dict["takes_address"]);
    $T->Set("status", $REPAIR_STATUS[$dict["status"]]);
    $T->Set("status_id", $dict["status"]);
    $T->Set("evaluate", $dict["evaluate"]);
    $T->Set("add_evaluate", $dict["add_evaluate"]);
    $T->Set("refuse_reason", $dict["refuse_reason"]);

    $sql = $T->db->query("select * from sys_takes_codes WHERE takes_id=".$id." and takes_stauts = 9")->fetchAll(PDO::FETCH_ASSOC);
    $out_yy = "";
    $html_show_center = "";
    switch($dict["status"]){
        case "9":
            foreach($sql as $val){
                $out_yy.=$member_list[$val["takes_user_id"]]."&nbsp;&nbsp;&nbsp;&nbsp;".$val["takes_code"]."<br/>";
            }
            $html_show_center.= '<tr id="evaluate_tr_content"><td>拒绝人和拒绝原因</td>';
            $html_show_center.= '<td colspan="5">'.$out_yy.'</td></tr>';
            break;
        default:
            $sql = "select * from sys_takes_codes where takes_id=".$id." and takes_user_id='".$_SESSION['uid']."' and takes_stauts=".$dict["status"];
            $one_list = $T->db->query($sql)->fetch(PDO::FETCH_ASSOC);
            if($_SESSION['role'] == 5){
                $code = $dict["remarks"];
            }else{
                $code =$one_list['takes_code'];
            }

            $html_show_center.= '<tr id="refuse_reason"><td>备注</td><td colspan="5">';
            $html_show_center.= $code.'</td></tr>';
            break;
    }

    $T->Set("html_show_center",$html_show_center);


}else{
    $T->Set("id","");
}
//$T->SetBlock("list_department","SELECT id,deptname FROM sys_department");
//$T->SetBlock("repair_type","SELECT * FROM sys_equipment_repair where is_flag_delete = 0 order by id desc");
$T->Set("template",$template);         
$T->clearNaN();       
$T->clearNoN();
$T->display(); 